XdmModule.NativeModule<T> MethodXdmModule.NativeModule(Of T) MethodXdmModule::NativeModule<T> Method

Returns a module defined by a native .NET type.

Syntax

Public Shared Function NativeModule(Of T)() As XdmModule
public static XdmModule NativeModule<T>()
public:
generic <T>
static XdmModule^ NativeModule<T>()
 

Type Parameters

T

The type that contains methods to expose.

Return Value

Type: XmlPrime.XdmModuleXmlPrime.XdmModuleXmlPrime::XdmModule^

A new instance of XdmModuleXdmModuleXdmModule containing functions representing methods from T.

Exceptions

ExceptionCondition
InvalidOperationExceptionInvalidOperationExceptionInvalidOperationException An InvalidOperationExceptionInvalidOperationExceptionInvalidOperationException is raised in the following conditions:

Remarks

For an example of the use of this function, see Modules.

Libraries of functions can be made available to an XQuery program, XPath expression or XSL transformation by adding them to the LibrariesLibrariesLibraries collection.

If T is annotated with the XdmModuleAttributeXdmModuleAttributeXdmModuleAttribute then the target namespace can be specified by the attribute. If the attribute is not present, or the namespace is not declared, then the namespace of the function library is a uri with the scheme clitype. The path of the URI is the full CLI name of the type.

Here are some examples:
TypeURI
MathMathMathclitype:System.Math
decimalDecimaldecimalclitype:System.Decimal
SpecialFolderSpecialFolderSpecialFolder clitype:System.Environment+SpecialFolder (note that this is an enumeration, and as such has no static methods to import, but this still serves as an example of how to reference a nested type)

T must be a non-generic class, otherwise a NotSupportedExceptionNotSupportedExceptionNotSupportedException is thrown.

 
 
Warning
Note that in order to ensure well defined behaviour, all functions used from within the XQuery program, XPath expression or XSL transformation should be pure and deterministic (that is, they should have no side-effects and the value returned from the function must depend only on the values of its arguments). How many times each function is called, whether the function is called and the order in which functions are called is undefined and will change based on how the query is optimized.
 

If T is annotated with the XdmModuleAttributeXdmModuleAttributeXdmModuleAttribute attribute, then all public static methods annotated with the XdmFunctionAttributeXdmFunctionAttributeXdmFunctionAttribute attribute are exported. The XdmFunctionAttributeXdmFunctionAttributeXdmFunctionAttribute attribute can be used to declare the local name of the exported function. If the XdmFunctionAttributeXdmFunctionAttributeXdmFunctionAttribute attribute does not declare a local name then the name of the method is used. If any public static method marked with the XdmFunctionAttributeXdmFunctionAttributeXdmFunctionAttribute attribute does not satisfy the conditions below then an InvalidOperationExceptionInvalidOperationExceptionInvalidOperationException is thrown.

If T is not annotated with the XdmModuleAttributeXdmModuleAttributeXdmModuleAttribute attribute then all the public static methods of T and its base types which satisfy all the following conditions are exposed. The methods are exported as functions with the same name as the method. Any XdmFunctionAttributeXdmFunctionAttributeXdmFunctionAttribute attributes are ignored.

  • The method is public.
  • The method is static.
  • The method is not a generic method.
  • The exported name of the method is a valid NCName value.
  • The name of all the parameters are valid NCName values.
  • The return type is supported.
  • All the parameter types are supported.
  • None of the parameters are ref or out parameters.
  • None of the parameters are variable length argument lists.
  • If the method is overloaded, then no overload has the same number of arguments.

If a method has the same exported name and number of arguments as a method in a base class, then the base class methods with the same name and number of arguments are excluded.